package com.dt76.smallloanbackenduser.controller.jh;

import com.dt76.smallloanbackenduser.pojo.jh.DataTemplate;
import com.dt76.smallloanbackenduser.pojo.jh.SortRegisterUserInfo;
import com.dt76.smallloanbackenduser.remote.jh.LoasituationRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/jh")
public class LoasituationController {


    @Autowired
    private LoasituationRemote loasituationRemote;

    @GetMapping("/toLoasituation")
    public String toLoasituation() {
        return "pages/jiang/Loasituation";
    }

    @GetMapping("/qryThenumberAll")
    @ResponseBody
      public Map<String, Object> thenumber(Model model){
        Map<String, List<DataTemplate>> listMap = loasituationRemote.qryThenumberAll();
        List<DataTemplate> list1 =  listMap.get("list1");
        for (DataTemplate dataTemplate : list1) {
            System.out.println(dataTemplate.getA_count() + "aaa");
        }
        double[] Thenumbers = new double[list1.size()];
        for (int i = 0; i<list1.size();i++){
            Thenumbers[i] = Double.valueOf(list1.get(i).getA_count());
        }
        List<DataTemplate> list2 =  listMap.get("list2");
        double[] moneys = new double[list2.size()];
        for (int i = 0; i<list2.size();i++){
            moneys[i] = Double.valueOf(list2.get(i).getANY_VALUE());
        }
        List<DataTemplate> list3 =  listMap.get("list3");
        double[] Ids = new double[list3.size()];
        for (int i = 0; i<list3.size();i++){
            Ids[i] = Double.valueOf(list3.get(i).getA_count());
        }
        System.out.println("调用成功");
        double[] sampleA = Thenumbers;
        double[] sampleB = moneys;
        double[] sampleC = Ids;
        Map<String, Object> map = new HashMap<>();
        map.put("serieA", new SortRegisterUserInfo("贷款人数",sampleA));
        map.put("serieB", new SortRegisterUserInfo("放款金额",sampleB));
        map.put("serieC", new SortRegisterUserInfo("放款人数",sampleC));
        return map;
    }


}
